<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>OverType - Basic Example</title>
    <style>
        body {
            font-family: system-ui, -apple-system, sans-serif;
            max-width: 900px;
            margin: 0 auto;
            padding: 40px 20px;
            background: #f5f5f5;
        }
        
        h1 {
            color: #333;
            margin-bottom: 10px;
        }
        
        .subtitle {
            color: #666;
            margin-bottom: 30px;
        }
        
        .editor-container {
            height: 400px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        
        .controls {
            margin-top: 20px;
            display: flex;
            gap: 10px;
        }
        
        button {
            padding: 8px 16px;
            border: none;
            background: #4a90e2;
            color: white;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
        }
        
        button:hover {
            background: #357abd;
        }
        
        .output {
            margin-top: 20px;
            padding: 15px;
            background: #f9f9f9;
            border: 1px solid #e0e0e0;
            border-radius: 4px;
            white-space: pre-wrap;
            font-family: monospace;
            font-size: 13px;
            max-height: 200px;
            overflow-y: auto;
        }
    </style>
</head>
<body>
    <h1>OverType Basic Example</h1>
    <p class="subtitle">A simple markdown editor with live preview</p>
    
    <div id="editor" class="editor-container"></div>
    
    <div class="controls">
        <button onclick="toggleTheme()">Toggle Theme</button>
        <button onclick="getValue()">Get Value</button>
        <button onclick="setValue()">Set Sample Content</button>
        <button onclick="clearEditor()">Clear</button>
    </div>
    
    <div id="output" class="output" style="display: none;"></div>

    <script src="../dist/overtype.js"></script>
    <script>
        // Initialize the editor
        const OT = window.OverType?.default || window.OverType;
        const [editor] = new OT('#editor', {
            placeholder: 'Start typing markdown...',
            value: `# Welcome to OverType!

This is a **lightweight** markdown editor with *perfect* character alignment.

## Features

- Real-time preview
- Keyboard shortcuts (Cmd/Ctrl + B for bold, I for italic)
- Multiple themes
- Zero dependencies

## Try It Out

1. Type some markdown
2. Use keyboard shortcuts
3. Toggle the theme

> The preview updates as you type!

## Code Example

\`\`\`
// Code blocks now have background styling!
function greet(name) {
    return \`Hello, \${name}!\`;
}
\`\`\`

Inline \`code\` also works great!

[Learn more](https://github.com/demo/overtype)`,
            onChange: (value, instance) => {
                console.log('Content changed:', value.length + ' characters');
            }
        });

        let currentTheme = 'solar';

        function toggleTheme() {
            currentTheme = currentTheme === 'solar' ? 'cave' : 'solar';
            OT.setTheme(currentTheme);
            console.log('Theme changed to:', currentTheme);
        }

        function getValue() {
            const value = editor.getValue();
            const output = document.getElementById('output');
            output.textContent = value;
            output.style.display = 'block';
            console.log('Editor value:', value);
        }

        function setValue() {
            const sampleContent = `# Sample Document

This is some **sample content** to demonstrate the \`setValue\` method.

## Shopping List

- Milk
- Bread
- Eggs
- Coffee

## Code Example

\`\`\`javascript
function hello() {
    console.log("Hello, OverType!");
}
\`\`\`

---

*Generated at ${new Date().toLocaleString()}*`;
            
            editor.setValue(sampleContent);
            console.log('Content set');
        }

        function clearEditor() {
            editor.setValue('');
            document.getElementById('output').style.display = 'none';
            console.log('Editor cleared');
        }

        // Log keyboard shortcuts for reference
        console.log('Keyboard shortcuts:');
        console.log('  Cmd/Ctrl + B: Bold');
        console.log('  Cmd/Ctrl + I: Italic');
        console.log('  Cmd/Ctrl + K: Code');
        console.log('  Cmd/Ctrl + Shift + 7: Numbered list');
        console.log('  Cmd/Ctrl + Shift + 8: Bullet list');
    </script>
</body>
</html>